package com.cos.hospital.widget;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * 简单 不需要注释
 * Created by yby on 2018/9/30
 */
public class MyRecyclerView extends RecyclerView {
    private ScrollListener scrollListener;

    public MyRecyclerView(Context context) {
        super(context);
    }

    public MyRecyclerView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public MyRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (scrollListener != null) {
            scrollListener.onStateChanged(ev.getAction() == MotionEvent.ACTION_MOVE);
        }
        return super.onInterceptTouchEvent(ev);
    }

    public void setScrollListener(ScrollListener scrollListener) {
        this.scrollListener = scrollListener;
    }

    public interface ScrollListener {
        void onStateChanged(boolean isMoving);
    }
}
